package com.sikaryofficial.backend.config;

import com.github.houbb.sensitive.word.api.IWordAllow;
import com.github.houbb.sensitive.word.api.IWordDeny;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.allow.WordAllows;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import com.github.houbb.sensitive.word.support.ignore.SensitiveWordCharIgnores;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : qinjinyuan
 * @desc : 敏感词配置
 * @date : 2024/03/11 10:05
 */
@Configuration
public class SpringSensitiveWordConfig {

    @Autowired
    private MyWordAllow myDdWordAllow;

    @Autowired
    private MyWordDeny myDdWordDeny;

    /**
     * 初始化引导类
     *
     * @return 初始化引导类
     * @since 1.0.0
     */
    @Bean
    public SensitiveWordBs sensitiveWordBs() {
        // 敏感词 = 系统 + 自定义
        IWordDeny wordDeny = WordDenys.chains(WordDenys.defaults(), myDdWordDeny);
        // 白名单 = 系统 + 自定义
        IWordAllow wordAllow = WordAllows.chains(WordAllows.defaults(), myDdWordAllow);
        return SensitiveWordBs.newInstance()
                .wordAllow(wordAllow)
                .wordDeny(wordDeny)
                .charIgnore(SensitiveWordCharIgnores.specialChars())
                // 各种其他配置
                .numCheckLen(8)
                .enableUrlCheck(false)
                // 不启用数字校验
                .enableNumCheck(false)
                .init();
    }
}
